/**
 * Buffer.h
 *
 *  Created on: 22.03.2010
 *      Author: Gott2
 *
 *      Buffer reads fixed amount of char from file.
 *
 */

#ifndef BUFFER_H_
#define BUFFER_H_

#include <stdio.h>
#include <iostream>
#include "../Exceptions/FileNotFoundException.h"

class Buffer {
private:

	FILE* sourcecode;

	int buffer_size;

	char* buffer1;

	char* buffer2;

	/*
	 * current selected buffer
	 */
	char* currentBuffer;

	/*
	 * Current index in the buffer
	 */
	int currentIndex;

	/*
	 *
	 */
	bool isUngetChar;


	/**
	 * Switch the current used buffer
	 */
	virtual void switchBuffer();
	/**
	 * Fill the current buffer with sourcecode
	 */
	virtual void reloadBuffer();


public:
	/**
	 * filename - Quellcodelocation
	 * buffer_size - Size of the Buffer(Optiomal = 1024)(Default = 1024)
	 */
	Buffer(char* filename,int buffer_size = 1024);
	/**
	 * Get a char from the sourceocde
	 */
	virtual char getChar();
	/**
	 * Get the previous char from the sourcecode
	 */
	virtual char ungetChar();
	virtual ~Buffer();
};

#endif /* BUFFER_H_ */
